package com.bigegg.employee.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.bigegg.employee.domain.Board;
import com.bigegg.employee.service.IBoardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招聘公告Controller
 * 
 * @author sun
 * @date 2022-08-15
 */
@RestController
@RequestMapping("/employee/board")
public class BoardController extends BaseController
{
    @Autowired
    private IBoardService boardService;

    /**
     * 查询招聘公告列表
     */
    @PreAuthorize("@ss.hasPermi('employee:board:list')")
    @GetMapping("/list")
    public TableDataInfo list(Board board)
    {
        startPage();
        List<Board> list = boardService.selectBoardList(board);
        return getDataTable(list);
    }

    /**
     * 导出招聘公告列表
     */
    @PreAuthorize("@ss.hasPermi('employee:board:export')")
    @Log(title = "招聘公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Board board)
    {
        List<Board> list = boardService.selectBoardList(board);
        ExcelUtil<Board> util = new ExcelUtil<Board>(Board.class);
        util.exportExcel(response, list, "招聘公告数据");
    }

    /**
     * 获取招聘公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:board:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(boardService.selectBoardById(id));
    }

    /**
     * 新增招聘公告
     */
    @PreAuthorize("@ss.hasPermi('employee:board:add')")
    @Log(title = "招聘公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Board board)
    {
        return toAjax(boardService.insertBoard(board));
    }

    /**
     * 修改招聘公告
     */
    @PreAuthorize("@ss.hasPermi('employee:board:edit')")
    @Log(title = "招聘公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Board board)
    {
        return toAjax(boardService.updateBoard(board));
    }

    /**
     * 删除招聘公告
     */
    @PreAuthorize("@ss.hasPermi('employee:board:remove')")
    @Log(title = "招聘公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(boardService.deleteBoardByIds(ids));
    }
}
